package top.syfy.spb.upload.imageandwatermark.response;

import top.syfy.spb.upload.imageandwatermark.constant.ContentReturnEnum;
import java.io.Serializable;
import java.util.Objects;

/**
 * 统一的响应类
 *
 * @author awg
 * @date 2020/10/23 星期五
 */
public class ContentReturnType implements Serializable {

    private static final long serialVersionUID = 9028168249190564462L;

    /**
     * 响应状态码
     */
    private Integer code;
    /**
     * 响应信息
     */
    private String msg;
    /**
     * 返回的具体数据
     */
    private Object data;

    private ContentReturnType(Integer returnCode, String returnMsg, Object returnData) {
        this.code = returnCode;
        this.msg = returnMsg;
        this.data = returnData;
    }

    /**
     * 统一的响应返回
     *
     * @param resultEnum 请求响应的状态码及响应信息的枚举类
     * @param responseData 需要返回的数据
     * @return JSON格式的返回信息
     */
    public static ContentReturnType ofReturn(ContentReturnEnum resultEnum, Object responseData) {
        if (Objects.isNull(resultEnum)) {
            return ContentReturnType.ofReturn(ContentReturnEnum.REQUEST_ENTITY_TOO_LARGE, null);
        }
        return new ContentReturnType(resultEnum.getCode(), resultEnum.getMsg(), responseData);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
